<% local_domain = "#{request.protocol}#{request.host_with_port}" %>

<h1 class="page-not-found"><%= t 'page_not_found.title' %></h1>

<div class="row page-not-found-topics">
  <div class="span8 popular-topics">
    <h2 class="popular-topics-title"><%= t 'page_not_found.popular_topics' %></h2>
    <% @top_viewed.each do |t| %>
      <div class='not-found-topic'>
        <%= link_to t.title, t.relative_url %><%= category_badge(t.category) %>
      </div>
    <% end %>
    <br/>
    <a href="<%= path "/latest" %>" class="btn"><%= t 'page_not_found.see_more' %>&hellip;</a>
  </div>
  <div class="span8 recent-topics">
    <h2 class="recent-topics-title"><%= t 'page_not_found.recent_topics' %></h2>
    <% @recent.each do |t| %>
      <div class='not-found-topic'>
        <%= link_to t.title, t.relative_url %><%= category_badge(t.category) %>
      </div>
    <% end %>
    <br/>
    <a href="<%= path "/latest" %>" class="btn"><%= t 'page_not_found.see_more' %>&hellip;</a>
  </div>
</div>

<%- unless @hide_google %>
  <div class="row">
    <div class="span10 page-not-found-search">
      <h2><%= t 'page_not_found.search_title' %></h2>
      <p>
        <form action='//google.com/search' id='google-search' onsubmit="return google_button_clicked()">
          <input type="text" id='user-query' value="<%= @slug %>">
          <input type='hidden' id='google-query' name="q">
          <button class="btn btn-primary"><%= t 'page_not_found.search_google' %></button>
        </form>
      </p>
    </div>
  </div>

  <script language="Javascript">
    function google_button_clicked(e) {
      var searchValue = document.getElementById('user-query').value;
      document.getElementById('google-query').value = 'site:<%= local_domain %> ' + searchValue;
      return true;
    }

    window.onpopstate = function(event) {
      if (event.state && !window.hasOwnProperty("Discourse")) {  //check if Discourse object exists if not take care of back navigation
        window.location = document.location;
      }
    };
  </script>
<%- end %>
